package com.xzwk.subject.domain.handler.subject;

import com.xzwk.subject.common.enums.SubjectInfoTypeEnum;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

@Component
public class SubjectTypeHandlerFactory implements InitializingBean {

  @Resource
  private List<SubjectTypeHandler> subjectTypeHandlerList;

  private Map<SubjectInfoTypeEnum,SubjectTypeHandler> handlerMap=new HashMap<>();


  public SubjectTypeHandler getHandler(int subjectType){

    SubjectInfoTypeEnum subjectInfoTypeEnum = SubjectInfoTypeEnum.getByCode(subjectType);

    return handlerMap.get(subjectInfoTypeEnum);
  }


  @Override
  public void afterPropertiesSet() throws Exception {
    for (SubjectTypeHandler subjectTypeHandler:subjectTypeHandlerList){
      handlerMap.put(subjectTypeHandler.getHandlerType(),subjectTypeHandler);
    }
  }
}
